package com.qdu.web.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qdu.common.annotation.Log;
import com.qdu.common.core.controller.BaseController;
import com.qdu.common.core.domain.AjaxResult;
import com.qdu.common.enums.BusinessType;
import com.qdu.bussiness.domain.BusDelivery;
import com.qdu.bussiness.service.IBusDeliveryService;
import com.qdu.common.utils.poi.ExcelUtil;
import com.qdu.common.core.page.TableDataInfo;

/**
 * 出库信息Controller
 * 
 * @author qdu
 * @date 2022-03-06
 */
@RestController
@RequestMapping("/bussiness/delivery")
public class BusDeliveryController extends BaseController
{
    @Autowired
    private IBusDeliveryService busDeliveryService;

    /**
     * 查询出库信息列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusDelivery busDelivery)
    {
        startPage();
        List<BusDelivery> list = busDeliveryService.selectBusDeliveryList(busDelivery);
        return getDataTable(list);
    }

    /**
     * 导出出库信息列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:export')")
    @Log(title = "出库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusDelivery busDelivery)
    {
        List<BusDelivery> list = busDeliveryService.selectBusDeliveryList(busDelivery);
        ExcelUtil<BusDelivery> util = new ExcelUtil<BusDelivery>(BusDelivery.class);
        util.exportExcel(response, list, "出库信息数据");
    }

    /**
     * 获取出库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:query')")
    @GetMapping(value = "/{deliveryId}")
    public AjaxResult getInfo(@PathVariable("deliveryId") Long deliveryId)
    {
        return AjaxResult.success(busDeliveryService.selectBusDeliveryByDeliveryId(deliveryId));
    }

    /**
     * 新增出库信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:add')")
    @Log(title = "出库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDelivery busDelivery)
    {
        if(busDelivery.getDeliveryNum() == null || busDelivery.getDeliveryNum() <= 0){
            return AjaxResult.error("出库数量应大于0！");
        }
        return busDeliveryService.insertBusDelivery(busDelivery);
    }

    /**
     * 修改出库信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:edit')")
    @Log(title = "出库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDelivery busDelivery)
    {
        return toAjax(busDeliveryService.updateBusDelivery(busDelivery));
    }

    /**
     * 删除出库信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:delivery:remove')")
    @Log(title = "出库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deliveryIds}")
    public AjaxResult remove(@PathVariable Long[] deliveryIds)
    {
        return toAjax(busDeliveryService.deleteBusDeliveryByDeliveryIds(deliveryIds));
    }
}
